package com.zhu.storesmanager;


import com.zhu.storesmanager.models.RemindItemInfo;
import com.zhu.storesmanager.provider.StoresManagerSettings;
import com.zhu.storesmanager.utils.Actions;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

/**
 * 提醒内容显示界面
 */

public class RemindContentActivity extends Activity implements View.OnClickListener{

	private RemindItemInfo mInfo = null; //数据
	private TextView mContentView = null; //内容
	private TextView mTitleView = null; //标题栏

	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_remindcontent);

        //获取传递过来的数据
        Parcelable parcelable = getIntent().getParcelableExtra("info");
        mInfo = (RemindItemInfo) parcelable;

        setupView();
        initData();
    }

	public void onResume() {
        super.onResume();
        Actions.setAutoTime(this);
    }

	/**
	 *初始化界面 
	 */
	private void setupView(){
		findViewById(R.id.remindcontent_bottom_delete).setOnClickListener(this);
		findViewById(R.id.remindlist_bottom_back).setOnClickListener(this);
    	mContentView = (TextView)findViewById(R.id.remindcontent_content);
    	mTitleView = (TextView) findViewById(R.id.title_text);
    }

	/**
	 * 初始化数据
	 */
    private void initData(){
    	mTitleView.setText(R.string.main_notification);
    	mContentView.setText(mInfo.mName + "(" +mInfo.mRangeName+")");
    }

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		if(arg0 != null){
        	switch(arg0.getId()){
        		case R.id.remindcontent_bottom_delete://删除
        			delete();
        			break;
        		case R.id.remindlist_bottom_back: //返回
        			finish();
        			break;
        	}
		}
	}

	/**
	 * 删除提醒
	 */
	private void delete(){
		String where = "";
        String eventWhere = "";
        if (where.length() == 0) {
        	where += StoresManagerSettings.RemindsColumns._ID + " = " + mInfo.id;
        	eventWhere += StoresManagerSettings.RemindsColumns._ID + " = " + mInfo.eventId;
        } else {
        	where += " or " + StoresManagerSettings.RemindsColumns._ID + " = " + mInfo.id;
        	eventWhere += " or " +StoresManagerSettings.RemindsColumns._ID + " = " + mInfo.eventId;
        }
        Actions.deleteEvent(this, eventWhere);
        getContentResolver().delete(StoresManagerSettings.RemindsColumns.CONTENT_URI, where, null);
        Actions.toastShort(this, getResources().getString(R.string.delete_success));
        setResult(RESULT_OK);
        finish();
	}
}
